package com.nana.petadventure.ui.scene
{
	import com.nana.framework.base.App;
	import com.nana.framework.ui.PSprite;
	
	import flash.display.DisplayObject;
	
	public class BackgroundSprite extends PSprite
	{
		private var _distanceRate:Number;
		private var _bitmapClass:Class;
		
		public function BackgroundSprite(bmClass:Class = null, disRate:int = 1)
		{
			super();
			this.x = 0;
			this.distanceRate = disRate;
			this.bitmapClass = bmClass;
		}
		
		public function loadView():void {
			this.removeAllChildren();
			var curWidth:int = 0;
			while(curWidth < App.appStage.width) {
				var bgpiece:DisplayObject = new this.bitmapClass;
				bgpiece.x = curWidth;
				bgpiece.y = 0;
				this.addChild(bgpiece);
				curWidth += bgpiece.width;
			}
		}
		
		// 重复画面   较为简单的实现
		public function move(spd:Number):void {
			if (this.x <= -this.width/2)
			{
				this.x = 0;
			}
			this.x -= spd / this.distanceRate;
		}

		public function get distanceRate():Number
		{
			return _distanceRate;
		}

		public function set distanceRate(value:Number):void
		{
			_distanceRate = value;
		}

		public function get bitmapClass():Class
		{
			return _bitmapClass;
		}

		public function set bitmapClass(value:Class):void
		{
			_bitmapClass = value;
		}


	}
}